﻿using System;
using System.Linq;
using studentSubsidy.Models;
using studentSubsidy.Utils;

namespace studentSubsidy.Dao
{
    public class UploadDao
    {
        private MyDbContext DBContext = new MyDbContext();

        public void insertUploadFile(string fileName,string fileExtension,int userId,int projectId)
        {
            var applyFile = new Apply_File
            {
                file_id = GenerateID.GenForInt(),
                user_id = userId,
                project_id = projectId,
                file_type = fileExtension,
                file_name = fileName,
                upload_time = DateTime.Now.ToString("s")
            };
            DBContext.UploadFiles.Add(applyFile);
            DBContext.SaveChanges();
        }

        public void insertSignedFile(Signed_File signedFile)
        {
            DBContext.SignedFiles.Add(signedFile);
            DBContext.SaveChanges();
        }

        public void updateSignedStatus(int applyId)
        {
            Apply apply = DBContext.Applies.Where(p => p.apply_id == applyId).ToList().First();
            apply.isSigned = 2;
            DBContext.Update(apply);
            DBContext.SaveChanges();
        }
    }
}